package dht.simulation;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class GlobalVariables {
	public static double eps = 1e-12;
	public static int seed = 1234567;
	public static int ringLength = 500004;
	public static double diskTime = 0.00004;
	public static double masterDiskTime = 0.00004;
	public static double readLoadWeight = 1.0;
	public static double writeLoadWeight = 1.0;
	public static double minLoadRatio = 1.5;
	public static double minLoadToSplit = 50;
	public static double loadMeasureInterval = 1.0;

	public static int masterId = 1;
	public static double tableUpdateInterval = 0.5;
	public static double splitInterval = 0.1;
	public static int additionalSeconds = 10;

	public static String networkFile = "network.dat";

	public static int lambdaR = 1000000;
	public static int lambdaW = 100000;
	public static double secondPerPerid = 1;
	public static int period = 60;
	public static int fileNumber = 10000000;
	public static int fileBlockSize = 65536;
	public static int maxFileBlockNumber = 16;

	public static final int metaReadReqSize = 32;
	public static final int metaReadRespSize = 32;
	public static final int metaReadAckSize = 32;
	public static final int readReqSize = 32;
	public static final int readFwdSize = 32;
	public static final int readRespSize = 32;
	public static final int readFwdAckSize = 32;
	public static final int readAckSize = 32;
	public static final int writeReqSize = 32;
	public static final int writeFwdSize = 32;
	public static final int writeRespSize = 32;
	public static final int writeFwdAckSize = 32;
	public static final int writeAckSize = 32;
	public static final int tableReqSize = 32;
	public static final int tableRespSize = 32;
	public static final int tableAckSize = 32;
	public static final int splitReqSize = 32;
	public static final int splitRespSize = 32;
	public static final int splitAckSize = 32;
	public static final int splitMoveReqSize = 32;
	public static final int splitMoveRespSize = 32;
	public static final int splitMoveAckSize = 32;
	public static final int splitFlushReqSize = 32;
	public static final int splitFlushRespSize = 32;
	public static final int splitFlushAckSize = 32;

	public static void initialize(String propertiesFile)
			throws FileNotFoundException, IOException {
		Properties properties = new Properties();
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(propertiesFile);
			properties.load(fis);
		} finally {
			fis.close();
		}

		seed = Integer.parseInt(properties.getProperty("seed"));
		ringLength = Integer.parseInt(properties.getProperty("ring-length"));
		diskTime = Double.parseDouble(properties.getProperty("disk-time"));
		masterDiskTime = Double.parseDouble(properties
				.getProperty("master-disk-time"));
		readLoadWeight = Double.parseDouble(properties
				.getProperty("read-load-weight"));
		writeLoadWeight = Double.parseDouble(properties
				.getProperty("write-load-weight"));
		minLoadRatio = Double.parseDouble(properties
				.getProperty("min-load-ratio"));
		minLoadToSplit = Double.parseDouble(properties
				.getProperty("min-load-to-split"));
		loadMeasureInterval = Double.parseDouble(properties
				.getProperty("load-measure-interval"));

		masterId = Integer.parseInt(properties.getProperty("master-id"));

		tableUpdateInterval = Double.parseDouble(properties
				.getProperty("table-update-interval"));
		splitInterval = Double.parseDouble(properties
				.getProperty("split-interval"));

		additionalSeconds = Integer.parseInt(properties
				.getProperty("additional-seconds"));

		networkFile = properties.getProperty("network-file");

		lambdaR = Integer.parseInt(properties.getProperty("lambda-r"));
		lambdaW = Integer.parseInt(properties.getProperty("lambda-w"));

		secondPerPerid = Double.parseDouble(properties
				.getProperty("second-per-perid"));

		period = Integer.parseInt(properties.getProperty("period"));
		fileNumber = Integer.parseInt(properties.getProperty("file-number"));
		fileBlockSize = Integer.parseInt(properties
				.getProperty("file-block-size"));
		maxFileBlockNumber = Integer.parseInt(properties
				.getProperty("max-file-block-number"));

	}

}
